<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>萌推电商</title>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/main.css"/>
</head>
<%
    int id= Integer.valueOf(request.getParameter("str"));
    String name=null;
    String price=null;
    String number=null;
    try {
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        Class.forName("org.h2.Driver");
        /*url后面加的?useUnicode=true&characterEncoding=gbk，是为了处理向数据库中添加数据时出现乱码的问题。*/
        String url = "jdbc:h2:~/test5";
        con = DriverManager.getConnection(url, "sa", "sa");
        stmt = con.createStatement();
        String sql =  "select * from product where pr_id='"+id+"'";
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            name=rs.getString("pr_name");
            price=rs.getString("price");
            number=rs.getString("number");

        }
        rs.close();
        stmt.close();
        con.close();
    }catch (Exception e){e.getMessage();}
%>
<body>
<div class="topbar-wrap white">
    <div class="topbar-inner clearfix">
        <div class="topbar-logo-wrap clearfix">
            <h1 class="topbar-logo none"><a href="../index.jsp" class="navbar-brand">萌推电商</a></h1>
            <ul class="navbar-list clearfix">
                <li><a class="on" href="#">首页</a></li>
                <li><a href="#" target="#">网站首页</a></li>
            </ul>
        </div>
        <div class="top-info-wrap">
            <ul class="top-info-list clearfix">
                <li><a href="#">管理员</a></li>
                <li><a href="#">修改密码</a></li>
                <li><a href="#">退出</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="container clearfix">
    <div class="sidebar-wrap">
        <div class="sidebar-title">
            <h1>菜单</h1>
        </div>
        <div class="sidebar-content">
            <ul class="sidebar-list">
                <li>
                    <a href="#"><i class="icon-font">&#xe003;</i>人事管理</a>
                    <ul class="sub-menu">
                        <li><a href="design.html"><i class="icon-font">&#xe008;</i>部门管理</a></li>
                        <li><a href="design.html"><i class="icon-font">&#xe005;</i>员工管理</a></li>
                    </ul>
                </li>
                <li>
                    <a href="#"><i class="icon-font">&#xe018;</i>业务管理</a>
                    <ul class="sub-menu">
                         <li><a href="../UserManager/user.jsp"><i class="icon-font">&#xe046;</i>用户管理</a></li>
                        <li><a href="../ShopManager/shop.jsp"><i class="icon-font">&#xe033;</i>店铺管理</a></li>
                        <li><a href="product.jsp"><i class="icon-font">&#xe006;</i>商品管理</a></li>
                        <li><a href="../OrderManager/order.jsp"><i class="icon-font">&#xe006;</i>订单管理</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="#">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="product.jsp">商品管理</a><span class="crumb-step">&gt;</span><span>修改商品</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="/final/Upproduct?str=<%=request.getParameter("str")%>" method="post" id="myform" name="myform" >
                    <table class="insert-tab" width="100%">
                        <tbody>
                            <tr>
                            <th width="120">类型分类：</th>
                            <td>
                                <select name="type" id="catid" class="required">
                                    <option value="日常用品">日常用品</option>
                                    <option value="衣服鞋子">衣服鞋子</option>
                                    <option value="早餐零食">早餐零食</option>
                                    <option value="学习用具">学习用具</option>
                                </select>
                            </td>
                        </tr>
                            <tr>
                                <th>商品名：</th>
                                <td><input class="common-text" name="name" size="50" value="<%=name%>" type="text"  required="required"></td>
                            </tr>
                            <tr>
                                <th width="120">所在商店id：</th>
                                <td>
                                    <select name="shopid" id="" class="required">
                                        <%
                                            int sh_id=0;
                                            try {
                                                Connection con = null;
                                                Statement stmt = null;
                                                ResultSet rs = null;
                                                Class.forName("org.h2.Driver");
                                                /*url后面加的?useUnicode=true&characterEncoding=gbk，是为了处理向数据库中添加数据时出现乱码的问题。*/
                                                String url = "jdbc:h2:~/test5";
                                                con = DriverManager.getConnection(url, "sa", "sa");
                                                stmt = con.createStatement();
                                                String sql =  "select sh_id from shop ";
                                                rs = stmt.executeQuery(sql);
                                                while (rs.next()) {
                                                    sh_id=rs.getInt("sh_id");%>
                                        <option value="<%=sh_id%>"><%=sh_id%></option><%
                                            }
                                            rs.close();
                                            stmt.close();
                                            con.close();
                                        }catch (Exception e){e.getMessage();}
                                    %>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>单价：</th>
                                <td><input class="common-text" name="price" size="50" value="<%=price%>" type="number"  required="required"></td>
                            </tr>
                            <tr>
                                <th>数量：</th>
                                <td><input class="common-text" name="number" size="50" value="<%=number%>" type="number"  required="required"></td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="submit">
                                    <input class="btn btn6" onClick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
</body>
</html>